<html>
<head>
<style>
  .ace_editor {
    border: 0;
    width: auto;
    height: 100%;
    margin: 0;
    top:0;
    right:0;
    bottom:0;
    left:0;
    z-index: 10000;
    touch-action: none;
  }

  body {
    padding: 0px;
    margin: 0px;
    overflow: hidden;
    -ms-overflow-style: scrollbar;
  }
</style>
</head>
<body>
<textarea id="source">package com.sencha.gxt.explorer.client.model;

import java.util.ArrayList;
import java.util.List;

import com.sencha.gxt.data.shared.TreeStore;
import com.sencha.gxt.data.shared.TreeStore.TreeNode;
import com.sencha.gxt.explorer.client.ExplorerApp;

public abstract class ExampleModel {
  protected List<Category> categories = new ArrayList<Category>();

  public Example findExampleByName(String name) {
    List<Example> list = getExamplesAsList();
    for (int i = 0; i < list.size(); i++) {
      Example ex = list.get(i);
      if (ex.getName().equals(name)) {
        return ex;
      }
    }
    return null;
  }
  
  public Example findExample(String id) {
    List<Example> list = getExamplesAsList();
    for (int i = 0; i < list.size(); i++) {
      Example ex = list.get(i);
      if (ex.getId().equals(id)) {
        return ex;
      }
    }
    return null;
  }

  public List<Example> getExamplesAsList() {
    List<Example> list = new ArrayList<Example>();
    for (int i = 0; i < categories.size(); i++) {
      Category c = categories.get(i);
      for (int j = 0; j < c.getExamples().size(); j++) {
        list.add(c.getExamples().get(j));
      }
    }

    return list;
  }

  protected ExampleModel() {
    // protected to it isn't instantiated directly, except by generated subclass
  }

  public List<Category> getCategories() {
    return categories;
  }

  public List<TreeStore.TreeNode<NamedModel>> getModels() {
    List<TreeStore.TreeNode<NamedModel>> models = new ArrayList<TreeStore.TreeNode<NamedModel>>();
    for (final Category c : categories) {
      if (c.getName().equals(ExplorerApp.OVERVIEW_CATEGORY)) {
        continue;
      }
      final List<TreeStore.TreeNode<NamedModel>> examples = new ArrayList<TreeStore.TreeNode<NamedModel>>();
      for (final Example e : c.getExamples()) {
        examples.add(new TreeStore.TreeNode<NamedModel>() {
          @Override
          public List<? extends TreeNode<NamedModel>> getChildren() {
            return null;
          }

          @Override
          public NamedModel getData() {
            return e;
          }
        });
      }
      models.add(new TreeStore.TreeNode<NamedModel>() {
        @Override
        public List<? extends TreeNode<NamedModel>> getChildren() {
          return examples;
        }

        @Override
        public NamedModel getData() {
          return c;
        }
      });
    }

    return models;
  }

}
</textarea>

<script src="../../samples/ace/ace.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
  var type = "{type}";
  if (type == ("{" + "type}")) {
    // something went wrong, use java as default
    type = "java";
  }
  var editor = ace.edit("source");
  var mode = "ace/mode/" + type;
  var theme = "ace/theme/chrome";
  var readOnly = true;
  editor.getSession().setMode(mode);
  editor.getSession().setUseWorker(false);
  editor.setTheme(theme);
  editor.setShowPrintMargin(false);
  editor.renderer.setShowGutter(true);
  editor.setHighlightActiveLine(false);
  editor.setDisplayIndentGuides(true);
  editor.setReadOnly(readOnly);
  editor.renderer.setPadding(10);
  editor.renderer.setScrollMargin(10, 10, 0, 0);
  editor.getSession().setOptions({
    tabSize: 8,
    useSoftTabs: true,
    useWrapMode: false,
  });
</script>
</body>
</html>